#include <mysql/mysql.h>

bool db_insert(char *query) {
  MYSQL conn;
  mysql_init(&conn);
  if (mysql_real_connect(&conn, "localhost", "root", "newPwd", "httpx", 0, NULL,
                         CLIENT_FOUND_ROWS)) {
    int res = mysql_query(&conn, query);
    mysql_close(&conn);
    if (res) return false;
  } else return false;
  return true;
}

bool db_search(char *query) {
  MYSQL conn;
  mysql_init(&conn);
  if (mysql_real_connect(&conn, "localhost", "root", "newPwd", "httpx", 0, NULL,
                         CLIENT_FOUND_ROWS)) {
    int res = mysql_query(&conn, query);
    if(!res){
        int rows = mysql_num_rows(mysql_store_result(&conn));
        mysql_close(&conn);
        return rows > 0;
    }else{
        mysql_close(&conn);
        return false;
    }
    
  } else return false;
  return true;
}